package com.scu.mindtogether.controller;

import com.alibaba.fastjson.JSONObject;
import com.scu.mindtogether.service.LoginService;
import com.scu.mindtogether.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: hxy
 * @description: 登录相关Controller
 * @date: 2017/10/24 10:33
 */
@RestController
@RequestMapping("/login")
public class LoginController {

	@Autowired
	private LoginService loginService;

	/**
	 * 登录
	 */


	@PostMapping("/auth")
	public JSONObject authLogin(@RequestBody JSONObject requestJson) {
		CommonUtil.hasAllRequired(requestJson, "username,password");
		return loginService.authLogin(requestJson);
	}
//	@GetMapping("/auth")
//	public JSONObject authLogin(@RequestParam String username,@RequestParam String password) {
//		JSONObject tmp=new JSONObject();
//		tmp.put("username",username);
//		tmp.put("password",password);
//
//		CommonUtil.hasAllRequired(tmp, "username,password");
//		return loginService.authLogin(tmp);
//	}


	/**
	 * 查询当前登录用户的信息
	 */
	@PostMapping("/getInfo")
	public JSONObject getInfo() {
		return loginService.getInfo();
	}

	/**
	 * 登出
	 */
	@PostMapping("/logout")
	public JSONObject logout() {
		return loginService.logout();
	}
}
